package com.kdgc.power.business.controller;

import com.kdgc.power.business.entity.ComDict;
import com.kdgc.power.fw.bean.JsonMsg;
import com.kdgc.power.business.service.ComDictService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("ComDict")
public class ComCDictController {
    @Autowired
    private ComDictService comDictService;

    @ResponseBody
    @RequestMapping("page")
    public Object page(HttpServletRequest request, int page, int rows) {
        String catCode = request.getParameter("catCode");
        Map<String, Object> paras = new HashMap<>();
        paras.put("catCode", catCode);
        return comDictService.getPage("comDict.select", paras, page, rows);


    }

    @ResponseBody
    @RequestMapping("findById")
    public ComDict findComCDict(Integer id) {
        return comDictService.getEntity(id);
    }

    @ResponseBody
    @RequestMapping("save")
    public JsonMsg saveComCDict(ComDict comDict) {
        boolean success = comDictService.saveOrUpdate(comDict);
        return new JsonMsg(success);
    }

    @ResponseBody
    @RequestMapping("deleteById")
    public JsonMsg deleteById(Integer id) {
        int rows = comDictService.removeById(id);
        return new JsonMsg(rows == 1);
    }
    @ResponseBody
    @RequestMapping("getByCatCode")
    public List<Map<String, Object>> getByCatCode(String catCode) {
        return  comDictService.getByCatCode(catCode);
    }
}